package com.hyt.it.ogt.ks.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.it.ogt.ks.base.BaseController;
import com.hyt.it.ogt.ks.enums.BizStatusCode;
import com.hyt.it.ogt.ks.feign.KwClient;
import com.hyt.it.ogt.ks.feign.model.ExamDTO;
import com.hyt.it.ogt.ks.model.vo.ExamOfficePageVO;
import com.hyt.it.ogt.ks.model.vo.ExamOfficeRequestVO;
import com.hyt.loginfo.enums.SysSkinSettingCodeEnum;
import com.hyt.loginfo.model.Skin;
import com.hyt.loginfo.service.ISystemSkinService;
import com.hyt.model.PageParam;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;
import lombok.extern.slf4j.Slf4j;

/**
 *
 * 任务机构类
 */
@RestController
@RequestMapping("ks/exam/office/")
@Api(tags = "18.考试机构接口", value = "考试机构信息")
@ApiSort(18)
@Slf4j
public class ExamOfficeController extends BaseController {

    @Resource
    private ISystemSkinService iSystemSkinService;
    @Resource
    private KwClient kwClient;

    @ApiOperation(value = "18.1  短code获取机构信息", notes = "状态码：20000:成功")
    @ApiOperationSort(1)
    @GetMapping("/getExamOfficeInfo")
    public ApiResponse<Skin> getExamOfficeInfo(String shortCode) {

        try {
            Skin skin = iSystemSkinService.getSkinByShortCodeAndSysCode(shortCode, SysSkinSettingCodeEnum.getEnumByCode(SysSkinSettingCodeEnum.KS.getCode()));
            if (skin == null ) {
                log.error("短code获取机构信息-异常码{}", BizStatusCode.GET_EXAM_OFFICE_INFO_NONE.getCode());
                return ApiResponse.<Skin>builder().code(BizStatusCode.GET_EXAM_OFFICE_INFO_NONE.getCode()).build();
            }
            return ApiResponse.<Skin>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(skin)
                    .build();
        } catch (Exception e) {
            log.error("短code获取机构信息-异常码{}：{}", BizStatusCode.GET_EXAM_OFFICE_INFO_FAIL.getCode(), e);
            return ApiResponse.<Skin>builder().code(BizStatusCode.GET_EXAM_OFFICE_INFO_FAIL.getCode()).build();
        }
    }

    @ApiOperation(value = "18.2  获取机构任务列表", notes = "状态码：20000:成功")
    @ApiOperationSort(2)
    @GetMapping("/getExamOfficeList")
    public Object getExamOfficeList(PageParam<ExamOfficePageVO> pageParam, String officeId) {
        try {
            ExamOfficeRequestVO vo = new ExamOfficeRequestVO();
            vo.setOfficeId(officeId);
            vo.setPageParam(pageParam);
            String res = kwClient.queryExamOfficePage(vo);
            return res;
        } catch (Exception e) {
            log.error("获取机构任务列表_异常码{}：{}", BizStatusCode.GET_EXAM_OFFICE_LIST_FAIL.getCode(), e);
            return ApiResponse.<ExamDTO>builder().code(BizStatusCode.GET_EXAM_OFFICE_LIST_FAIL.getCode()).build();
        }
    }
}

  	